/*
 * @Date: 2023-02-12 17:23:14
 * @LastEditors: Zireael 1193875164@qq.com
 * @LastEditTime: 2023-03-08 20:53:45
 * @FilePath: \A19\backend\src\api\Create\ApiCreateTest.ts
 */
import { tests } from './../../shared/types/tests';
import { Test } from './../../utils/Classes/Test';
import { Global } from './../../Global/index';
import { ApiCall } from "tsrpc";
import { ReqCreateTest, ResCreateTest } from "../../shared/protocols/Create/PtlCreateTest";
import { test } from 'mocha';

export default async function (call: ApiCall<ReqCreateTest, ResCreateTest>) {
    const teacher = call.currentUser
    const { course, startTime, endTime, name, questions,status } = call.req

    const test = {
        course,
        startTime,
        endTime,
        name,
        questions,
        status
    }

    const result = await Global.collection('tests').insertOne(test)
    if(status === 'published'){
        new Test({
            ...test,
            _id:result.insertedId
        })
    }
    
    call.succ({})
}